/**
 * 获取页面可用区域高度
 * @param bottom 底部内容占用高度
 * @returns 中间可用高度区域
 */
export function getPageContentHeight(bottom: number): number {
  const { safeAreaInsets, statusBarHeight, screenHeight } = uni.getSystemInfoSync()
  let navBarHeight = 0

  try {
    const menuButtonInfo = uni.getMenuButtonBoundingClientRect()
    navBarHeight = menuButtonInfo.height + (menuButtonInfo.top - (statusBarHeight ?? 0)) * 2
  } catch (e) {
    console.error('Error getting menu button info:', e)
  }

  const topDistance = (statusBarHeight ?? 0) + navBarHeight + (safeAreaInsets?.top ?? 0)
  const contentHeight = screenHeight - topDistance - bottom // bottom is the height of the footer

  return contentHeight
}
